package com.ahotbrew.androiddropdown; 

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Spinner staticSpinner = (Spinner) findViewById(R.id.static_spinner);

		// Create an ArrayAdapter using the string array and a default spinner
		ArrayAdapter<CharSequence> staticAdapter = ArrayAdapter
				.createFromResource(this, R.array.brew_array,
						android.R.layout.simple_spinner_item);

		// Specify the layout to use when the list of choices appears
		staticAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		// Apply the adapter to the spinner
		staticSpinner.setAdapter(staticAdapter);

		Spinner dynamicSpinner = (Spinner) findViewById(R.id.dynamic_spinner);

		String[] items = new String[] { "Chai Latte", "Green Tea", "Black Tea" };

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, items);

		dynamicSpinner.setAdapter(adapter);

		dynamicSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				Log.v("item", (String) parent.getItemAtPosition(position));
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub
			}
		});
	}
}
